package com.huawei.hbase.tables;

import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.hbase.HBaseConfiguration;
import org.apache.hadoop.hbase.TableName;
import org.apache.hadoop.hbase.client.Admin;
import org.apache.hadoop.hbase.client.Connection;
import org.apache.hadoop.hbase.client.ConnectionFactory;

import java.io.IOException;

/**
 * @author liucheng
 * @since 0.1 2023-11-11 15:20
 **/
public class DeleteTable {
    public static void main(String[] args) throws IOException {
        Configuration conf = HBaseConfiguration.create();
        conf.set("hbase.zookeeper.quorum", "192.168.0.151");
        conf.set("hbase.zookeeper.property.clientPort", "2181");
        Connection connection = ConnectionFactory.createConnection(conf);
        Admin admin = connection.getAdmin();
        TableName tableName = TableName.valueOf("users");

        if (admin.tableExists(tableName)) {
            if (admin.isTableAvailable(tableName)) {
                admin.disableTable(tableName);
            }
            admin.deleteTable(tableName);
            System.out.println("删除表" + tableName + "成功");
        } else {
            System.out.println(tableName + "表不存在");
        }
    }
}
